//
//  XSMianDetailViewController.m
//  MeiLiYiChu
//
//  Created by mac on 16/2/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "XSMianDetailViewController.h"
#import "XSMain.h"

@interface XSMianDetailViewController ()<UIScrollViewDelegate>
{
    UIScrollView *scroll;
}
@end

@implementation XSMianDetailViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden =YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    XSView *view =[[XSView alloc]initWithBool:YES withString:@"宝贝详情"];
    
    [self.view addSubview:view];
    UIButton * btn =(UIButton *)[view viewWithTag:1];
    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
    
    self.automaticallyAdjustsScrollViewInsets =NO;
    UIBarButtonItem * item =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"button_back-iOS7"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem =item;
    
    scroll =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, self.view.bounds.size.height)];
    scroll.contentSize =CGSizeMake(_array.count *scroll.frame.size.width, scroll.frame.size.height);
    //设置弹性与分页
    scroll.pagingEnabled =YES;
    scroll.bounces =YES;
    scroll.delegate =self;
    [self.view addSubview:scroll];
    
    
    if (_current ==0)
    {
        for (int i = 0; i< _array.count; i++)
        {
            UIWebView * webView =[[UIWebView alloc]init];
            webView.frame =CGRectMake(self.view.bounds.size.width*i, 0, self.view.bounds.size.width, self.view.bounds.size.height);
            webView.tag =i;
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
            [scroll addSubview:webView];
            _current =webView.tag;
            
        }

    }
    else
    {
        for (NSInteger i = _current; i< _array.count; i++)
        {
            UIWebView * webView =[[UIWebView alloc]init];
            webView.frame =CGRectMake(self.view.bounds.size.width*i, 64, self.view.bounds.size.width, self.view.bounds.size.height);
            webView.tag =i;
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
            [scroll addSubview:webView];
            _current =webView.tag;
            
        }
    }
   
}
-(void)btn
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [scroll setContentOffset:CGPointMake(scroll.frame.size.width*_current, 0)];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //拖拽减速
    
}
-(void)back
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
